package base

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gm/app/common"
	"net/http"
)

type BaseController struct{}




//获取用户信息
func (base *BaseController) GetUserInfo(c *gin.Context) *common.LoginUserInfo {
	loginUserInfo, has := c.Get(common.CTX_LOGIN_USER_INFO_KEY)

	firstname := c.DefaultQuery("firstname", "Guest")
	lastname := c.Query("lastname") // 是 c.Request.URL.Query().Get("lastname") 的简写

	c.String(http.StatusOK, "Hello %s %s", firstname, lastname)


	fmt.Println(c)
	if !has { //初次获取无值，通过Server-Token重新设置（主要是非必登录接口获取用户信息处理）
		//base.setUser(c)
		loginUserInfo, has = c.Get(common.CTX_LOGIN_USER_INFO_KEY)
	}
	if has {
		userInfo, ok := loginUserInfo.(*common.LoginUserInfo)
		if ok {
			return userInfo
		}
	}
	return nil
}

